#include <nxos.h>

void stack_stack(int n);

void stack_stack(int n)
{
    char buf[2048] = {0};
    NX_MemZero(buf, 2048);
    NX_Printf("stack: %d\n", n);
    if (n < 0)
    {
        return;
    }
    else
    {
        stack_stack(n - 1);
    }
}

void test_write_invalid_addr(void * addr)
{
    NX_Addr * p = (NX_Addr *)addr;
    *p = 0;
}

void test_read_invalid_addr(void * addr)
{
    NX_Addr * p = (NX_Addr *)addr;
    NX_Addr q = *p;
    q++;
}

NX_Error TEST_Stack(char *cmdline)
{
    stack_stack(10);
#ifndef NX_CPU_64BIT
    test_read_invalid_addr((void *)0x90000000);
    test_write_invalid_addr((void *)0x90000000);

    test_read_invalid_addr((void *)0x00000000);
    test_write_invalid_addr((void *)0x00000000);
#else
    test_read_invalid_addr((void *)0x350000000);
    test_write_invalid_addr((void *)0x350000000);

    test_read_invalid_addr((void *)0x00000000);
    test_write_invalid_addr((void *)0x00000000);
#endif
    return NX_EOK;
}
